<%@ page contentType="text/html;charset=UTF-8" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
    <c:set var="ctx" value="${pageContext.request.contextPath}"/>

<html>
<head>
    <title>更换手机</title>
    <script>
        $(document).ready(function() {
            //聚焦第一个输入框
            $("#oldM").focus();
            //为inputForm注册validate函数
            $("#inputForm").validate({
                rules: {
                    oldM:{required: true},
                    newM:{required: true}
                },
                messages: {
                    oldM:{
                        required:"旧手机号不能为空"
                    },
                    newM:{
                        required:"新手机号不能为空"
                    }
                }
            });

            $("#submit_btn").click(function(){
                var oldM = $('#oldM').val();
                if(oldM==undefined || oldM=="" || oldM==null)
                {
                    alert("旧手机号不能为空");
                    return false;
                }
                var newM = $('#newM').val();
                if(newM==undefined || newM=="" || newM==null)
                {
                    alert("新手机号不能为空");
                    return false;
                }
                var code = $('#code').val();
                if(code==undefined || code=="" || code==null)
                {
                    alert("验证码不能为空");
                    return false;
                }
                var url = "${ctx}/settings/changeMobile";
                $.post(url,{"oldM":oldM,"newM":newM,"code":code},function(data){
                    alert(data.message);
                },"json");
            });
            $("#send_code").click(function(){
                var mobile = $('#newM').val();
                var url = "${ctx}/register/sendCode/"+mobile;
                $.getJSON(url,function(data){
                    alert(data.message);
                });
            });
        });
    </script>

</head>

<body>
<div class="container">
    <div class="content">
        <form id="inputForm" action="" method="post" class="form-horizontal">
            <div class="form-group">
                <h3 class="item-title">更换手机</h3>

                <div class="form-item">
                    <label for="">旧手机号</label>
                    <input type="text" class="form-control" id="oldM" name="oldM" placeholder="旧手机号" required="">
                </div>
                <div class="form-item">
                    <label for="">新手机号</label>
                    <input type="text" class="form-control" id="newM" name="newM" placeholder="新手机号" required="">
                </div>
                <div class="form-item">
                    <label for="">验证码</label>
                    <input type="text" class="form-control" id="code" name="code" placeholder="手机验证码" required=""
                            ><input id="send_code" class="btn btn-primary" type="button" value="发送验证码"/>&nbsp;
                </div>
            </div>
            <div>
                <input id="submit_btn" class="btn btn-primary" type="button" value="保存"/>&nbsp;
            </div>
        </form>
    </div>
</div>
</body>
</html>